package com.crm.business.crm.mapper;

import com.alibaba.fastjson.JSONObject;

import com.crm.common.crm.common.CrmModel;
import com.crm.common.crm.entity.BO.CrmRoiPutinPageBO;
import com.crm.common.crm.entity.PO.CrmReceivables;
import com.crm.common.crm.entity.PO.CrmRefund;
import com.crm.common.crm.entity.VO.CrmRoiStatisVO;
import com.crm.common.ka.core.entity.BasePage;
import com.crm.business.servlet.BaseMapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 回款表 Mapper 接口
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-05-28
 */
public interface CrmReceivablesMapper extends BaseMapper<CrmReceivables> {
    /**
     * 通过id查询回款数据
     *
     * @param id id
     * @param userId 用户ID
     * @return data
     */
    public CrmModel queryById(@Param("id") Integer id, @Param("userId") Long userId);

    BasePage<JSONObject> queryListByContractId(BasePage<JSONObject> page, @Param("contractId") Integer contractId, @Param("conditions") String conditions);

    /**
     * 根据回款编号查询分单回款总数据
     * @param number
     * @return
     */
    BigDecimal queryReceivablesByNumber(@Param("number") String number);

    /**
     * 根据合同编号查询审核中或通过的回款信息
     * @param contractId
     * @return
     */
    BigDecimal querySumMoneyByContractId(@Param("contractId") Integer contractId);

    Integer queryProductNumByContractId(@Param("contractId") Integer contractId);

    BigDecimal queryMoneyInExamineData(@Param("receivablesList") List<CrmReceivables> crmReceivablesList);

    Map<String, Integer> queryDataInExamineData(@Param("receivablesList") List<CrmReceivables> crmReceivablesList, @Param("refundList") List<CrmRefund> crmRefundList);

    Integer queryCountReceivablesByCustomerId(@Param("customerId") Integer customerId);

    Integer queryCountReceivablesByStudentId(@Param("studentId") Integer studentId);

    Integer queryOtherCheckStatusById(@Param("receivablesIds") List<Integer> receivablesIds);

    List<JSONObject> queryReceivablesByThreeOrderNo(@Param("threePartOrderNo") String threePartOrderNo);

    List<JSONObject> queryReceivablesByThreeOrderNoByChect(@Param("threePartOrderNo") String threePartOrderNo);

    List<JSONObject> queryReceivablesByStudentCell(@Param("studentCell") String studentCell);

    JSONObject queryFirstReceivablesByContractId(@Param("contractId") Integer contractId);

    /**
     * 根据合同编号查询通过的回款信息
     * @param contractId
     * @return
     */
    BigDecimal querySumMoneyByContractIdAndCheck(@Param("contractId") Integer contractId);

    List<Map<String,Object>> queryPutinStatis(@Param("data") List<Integer> customerIds,@Param("userIds") List<Long> userIds);

    List<Map<String,Object>> queryAllPutinStatis(@Param("data") List<Integer> customerIds,@Param("userIds") List<Long> userIds);

    public List<CrmRoiStatisVO> queryRoiStatis(@Param("startDate") String startDate, @Param("endDate") String endDate);

    public List<CrmRoiStatisVO> queryExpectRoiStatis(@Param("startDate") String startDate, @Param("endDate") String endDate);

    public BigDecimal queryReceivablesMoneyByData(@Param("data") CrmRoiPutinPageBO crmRoiPutinPageBO);

    public BigDecimal queryExpectReceivablesMoneyByData(@Param("data") CrmRoiPutinPageBO crmRoiPutinPageBO);

    public List<CrmRoiStatisVO> queryPutinStatisByFormDate(@Param("data") CrmRoiPutinPageBO crmRoiPutinPageBO);

    public List<CrmRoiStatisVO> queryExpectPutinStatisByFormDate(@Param("data") CrmRoiPutinPageBO crmRoiPutinPageBO);


}
